<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: TestApplLayer Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00208.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#pub-types">Public Types</a> &#124;
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="#pro-attribs">Protected Attributes</a> &#124;
<a href="#pri-methods">Private Member Functions</a>  </div>
  <div class="headertitle">
<div class="title">TestApplLayer Class Reference<div class="ingroups"><a class="el" href="a00506.html">applLayer - application layer modules</a></div></div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="TestApplLayer" --><!-- doxytag: inherits="BaseApplLayer" -->
<p>Test class for the application layer.  
 <a href="a00208.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="a00280_source.html">TestApplLayer.h</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for TestApplLayer:</div>
<div class="dyncontent">
<div class="center"><img src="a01036.png" border="0" usemap="#TestApplLayer_inherit__map" alt="Inheritance graph"/></div>
<center><span class="legend">[<a target="top" href="graph_legend.html">legend</a>]</span></center></div>
<div class="dynheader">
Collaboration diagram for TestApplLayer:</div>
<div class="dyncontent">
<div class="center"><img src="a01037.png" border="0" usemap="#TestApplLayer_coll__map" alt="Collaboration graph"/></div>
<center><span class="legend">[<a target="top" href="graph_legend.html">legend</a>]</span></center></div>

<p><a href="a01038.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-types"></a>
Public Types</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00208.html#a3d99b89890ea7f156487ab5570f5b898">TestApplMessageKinds</a> { <b>SEND_BROADCAST_TIMER</b> =  LAST_BASE_APPL_MESSAGE_KIND, 
<b>BROADCAST_MESSAGE</b>, 
<b>BROADCAST_REPLY_MESSAGE</b>, 
<b>LAST_TEST_APPL_MESSAGE_KIND</b>
 }</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Message kinds used by this layer. <br/></td></tr>
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00208.html#a8df32483962ebc40e1eed225716e54cb">initialize</a> (int)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialization of the module and some variables.  <a href="#a8df32483962ebc40e1eed225716e54cb"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00208.html#a7cc6a018758d27f31133de05804281f8">handleSelfMsg</a> (cMessage *)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Handle self messages such as timer...  <a href="#a7cc6a018758d27f31133de05804281f8"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00208.html#af64945ae392b392418574b58b76232b9">handleLowerMsg</a> (cMessage *)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Handle messages from lower layer.  <a href="#af64945ae392b392418574b58b76232b9"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00208.html#aacf2004acd42e50fe4c46bdc3dcffbc2">sendBroadcast</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">send a broadcast packet to all connected neighbors  <a href="#aacf2004acd42e50fe4c46bdc3dcffbc2"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="af1d3f3a3be9478119f118beeb5b4ad85"></a><!-- doxytag: member="TestApplLayer::sendReply" ref="af1d3f3a3be9478119f118beeb5b4ad85" args="(ApplPkt *msg)" -->
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00208.html#af1d3f3a3be9478119f118beeb5b4ad85">sendReply</a> (ApplPkt *msg)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">send a reply to a broadcast message <br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-attribs"></a>
Protected Attributes</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ae46c2fd464821d8ffb07fc0588623d23"></a><!-- doxytag: member="TestApplLayer::delayTimer" ref="ae46c2fd464821d8ffb07fc0588623d23" args="" -->
cMessage *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00208.html#ae46c2fd464821d8ffb07fc0588623d23">delayTimer</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Timer message for scheduling next message. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a5efed246e454bf24dcbbf0fb1780df40"></a><!-- doxytag: member="TestApplLayer::coreDebug" ref="a5efed246e454bf24dcbbf0fb1780df40" args="" -->
bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00208.html#a5efed246e454bf24dcbbf0fb1780df40">coreDebug</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Enables debugging of this module. <br/></td></tr>
<tr><td colspan="2"><h2><a name="pri-methods"></a>
Private Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ad6e9b40e20dcb2ab4512a413debfdf0f"></a><!-- doxytag: member="TestApplLayer::TestApplLayer" ref="ad6e9b40e20dcb2ab4512a413debfdf0f" args="(const TestApplLayer &amp;)" -->
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00208.html#ad6e9b40e20dcb2ab4512a413debfdf0f">TestApplLayer</a> (const <a class="el" href="a00208.html">TestApplLayer</a> &amp;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Copy constructor is not allowed. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ab930eb650242dbb6110ee7e7d22db01d"></a><!-- doxytag: member="TestApplLayer::operator=" ref="ab930eb650242dbb6110ee7e7d22db01d" args="(const TestApplLayer &amp;)" -->
<a class="el" href="a00208.html">TestApplLayer</a> &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00208.html#ab930eb650242dbb6110ee7e7d22db01d">operator=</a> (const <a class="el" href="a00208.html">TestApplLayer</a> &amp;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Assignment operator is not allowed. <br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>Test class for the application layer. </p>
<p>In this implementation all nodes randomly send broadcast packets to all connected neighbors. Every node who receives this packet will send a reply to the originator node.</p>
<dl class="author"><dt><b>Author:</b></dt><dd>Daniel Willkomm </dd></dl>
</div><hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="af64945ae392b392418574b58b76232b9"></a><!-- doxytag: member="TestApplLayer::handleLowerMsg" ref="af64945ae392b392418574b58b76232b9" args="(cMessage *)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void TestApplLayer::handleLowerMsg </td>
          <td>(</td>
          <td class="paramtype">cMessage *&#160;</td>
          <td class="paramname"><em>msg</em></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Handle messages from lower layer. </p>
<p>There are two kinds of messages that can arrive at this module: The first (kind = BROADCAST_MESSAGE) is a broadcast packet from a neighbor node to which we have to send a reply. The second (kind = BROADCAST_REPLY_MESSAGE) is a reply to a broadcast packet that we have send and just causes some output before it is deleted </p>

<p>Reimplemented from <a class="el" href="a00016.html#a448cd52ea7a441a8f2edb3794a59205b">BaseApplLayer</a>.</p>

<p>Reimplemented in <a class="el" href="a00040.html#aaaf45ab3db0685c695394ea862a3d79f">BurstApplLayer</a>, and <a class="el" href="a00041.html#a66a2f76f5f30f1920dc65f00a6fd1ac3">BurstApplLayerBattery</a>.</p>

<p>References <a class="el" href="a00208.html#af1d3f3a3be9478119f118beeb5b4ad85">sendReply()</a>.</p>
<div class="fragment"><pre class="fragment">{
    ApplPkt *m;
    <span class="keywordflow">switch</span>( msg-&gt;getKind() ) {
    <span class="keywordflow">case</span> BROADCAST_MESSAGE:
        m = <span class="keyword">static_cast&lt;</span>ApplPkt *<span class="keyword">&gt;</span>(msg);
        coreEV &lt;&lt; <span class="stringliteral">&quot;Received a broadcast packet from host[&quot;</span>&lt;&lt;m-&gt;getSrcAddr()&lt;&lt;<span class="stringliteral">&quot;] -&gt; sending reply&quot;</span> &lt;&lt; endl;
        <a class="code" href="a00208.html#af1d3f3a3be9478119f118beeb5b4ad85" title="send a reply to a broadcast message">sendReply</a>(m);
        <span class="keywordflow">break</span>;
    <span class="keywordflow">case</span> BROADCAST_REPLY_MESSAGE:
        m = <span class="keyword">static_cast&lt;</span>ApplPkt *<span class="keyword">&gt;</span>(msg);
        coreEV &lt;&lt; <span class="stringliteral">&quot;Received reply from host[&quot;</span>&lt;&lt;m-&gt;getSrcAddr()&lt;&lt;<span class="stringliteral">&quot;]; delete msg&quot;</span> &lt;&lt; endl;
        <span class="keyword">delete</span> msg;
  <span class="keywordflow">break</span>;
    <span class="keywordflow">default</span>:
      EV &lt;&lt;<span class="stringliteral">&quot;Error! got packet with unknown kind: &quot;</span> &lt;&lt; msg-&gt;getKind()&lt;&lt;endl;
        <span class="keyword">delete</span> msg;
        <span class="keywordflow">break</span>;
    }
}
</pre></div>
</div>
</div>
<a class="anchor" id="a7cc6a018758d27f31133de05804281f8"></a><!-- doxytag: member="TestApplLayer::handleSelfMsg" ref="a7cc6a018758d27f31133de05804281f8" args="(cMessage *)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void TestApplLayer::handleSelfMsg </td>
          <td>(</td>
          <td class="paramtype">cMessage *&#160;</td>
          <td class="paramname"><em>msg</em></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Handle self messages such as timer... </p>
<p>A timer with kind = SEND_BROADCAST_TIMER indicates that a new broadcast has to be send (<a class="el" href="a00208.html#aacf2004acd42e50fe4c46bdc3dcffbc2">sendBroadcast</a>).</p>
<p>There are no other timer implemented for this module.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="a00208.html#aacf2004acd42e50fe4c46bdc3dcffbc2" title="send a broadcast packet to all connected neighbors">sendBroadcast</a> </dd></dl>

<p>Reimplemented from <a class="el" href="a00016.html#aba8356197b089f23dd9c19b6b7937dab">BaseApplLayer</a>.</p>

<p>Reimplemented in <a class="el" href="a00041.html#aa50363ece763f8c35957ce60fab0d9a3">BurstApplLayerBattery</a>, and <a class="el" href="a00040.html#ae3bd389dede2510650cfb8b32d5716b4">BurstApplLayer</a>.</p>

<p>References <a class="el" href="a00208.html#ae46c2fd464821d8ffb07fc0588623d23">delayTimer</a>, and <a class="el" href="a00208.html#aacf2004acd42e50fe4c46bdc3dcffbc2">sendBroadcast()</a>.</p>
<div class="fragment"><pre class="fragment">                                               {
    <span class="keywordflow">switch</span>( msg-&gt;getKind() ) {
    <span class="keywordflow">case</span> SEND_BROADCAST_TIMER:
        <a class="code" href="a00208.html#aacf2004acd42e50fe4c46bdc3dcffbc2" title="send a broadcast packet to all connected neighbors">sendBroadcast</a>();
    <span class="keyword">delete</span> msg;
    <a class="code" href="a00208.html#ae46c2fd464821d8ffb07fc0588623d23" title="Timer message for scheduling next message.">delayTimer</a> = NULL;
  <span class="keywordflow">break</span>;
    <span class="keywordflow">default</span>:
      EV &lt;&lt; <span class="stringliteral">&quot;Unknown selfmessage! -&gt; delete, kind: &quot;</span>&lt;&lt;msg-&gt;getKind() &lt;&lt;endl;
      <span class="keyword">delete</span> msg;
      <span class="keywordflow">break</span>;
    }
}
</pre></div>
</div>
</div>
<a class="anchor" id="a8df32483962ebc40e1eed225716e54cb"></a><!-- doxytag: member="TestApplLayer::initialize" ref="a8df32483962ebc40e1eed225716e54cb" args="(int)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void TestApplLayer::initialize </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>stage</em></td><td>)</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Initialization of the module and some variables. </p>
<p>First we have to initialize the module from which we derived ours, in this case <a class="el" href="a00031.html" title="Base class for all simple modules of a host that want to have access to the NotificationBoard module...">BasicModule</a>.</p>
<p>Then we will set a timer to indicate the first time we will send a message </p>

<p>Reimplemented from <a class="el" href="a00016.html#aa3ebaf5d1d1bdbec4648b07f65eb4145">BaseApplLayer</a>.</p>

<p>Reimplemented in <a class="el" href="a00040.html#ae693c2f1fc343d8c253778a1de1c4082">BurstApplLayer</a>, and <a class="el" href="a00041.html#a8ccaf74e9a310c5f45447283df6dee7e">BurstApplLayerBattery</a>.</p>

<p>References <a class="el" href="a00208.html#a5efed246e454bf24dcbbf0fb1780df40">coreDebug</a>, and <a class="el" href="a00208.html#ae46c2fd464821d8ffb07fc0588623d23">delayTimer</a>.</p>
<div class="fragment"><pre class="fragment">{
    <a class="code" href="a00208.html#a8df32483962ebc40e1eed225716e54cb" title="Initialization of the module and some variables.">BaseApplLayer::initialize</a>(stage);
    <span class="keywordflow">if</span>(stage == 0) {
      hasPar(<span class="stringliteral">&quot;coreDebug&quot;</span>) ? <a class="code" href="a00208.html#a5efed246e454bf24dcbbf0fb1780df40" title="Enables debugging of this module.">coreDebug</a> = par(<span class="stringliteral">&quot;coreDebug&quot;</span>).boolValue() : <a class="code" href="a00208.html#a5efed246e454bf24dcbbf0fb1780df40" title="Enables debugging of this module.">coreDebug</a> = <span class="keyword">false</span>;
        <a class="code" href="a00208.html#ae46c2fd464821d8ffb07fc0588623d23" title="Timer message for scheduling next message.">delayTimer</a> = <span class="keyword">new</span> cMessage( <span class="stringliteral">&quot;delay-timer&quot;</span>, SEND_BROADCAST_TIMER );
    }
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>(stage==1) {
        scheduleAt(simTime() + dblrand() * 10, <a class="code" href="a00208.html#ae46c2fd464821d8ffb07fc0588623d23" title="Timer message for scheduling next message.">delayTimer</a>);
    }
}
</pre></div>
</div>
</div>
<a class="anchor" id="aacf2004acd42e50fe4c46bdc3dcffbc2"></a><!-- doxytag: member="TestApplLayer::sendBroadcast" ref="aacf2004acd42e50fe4c46bdc3dcffbc2" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void TestApplLayer::sendBroadcast </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>send a broadcast packet to all connected neighbors </p>
<p>This function creates a new broadcast message and sends it down to the network layer </p>

<p>References <a class="el" href="a00016.html#ab42918350289ee246b194a5ab5e18d97">BaseApplLayer::headerLength</a>, <a class="el" href="a00117.html#a11d63e8d897e072ed94da77028d38f60">LAddress::L3BROADCAST</a>, <a class="el" href="a00016.html#a5b07d8afa4a3675a7e4c0d09dbbbddf3">BaseApplLayer::myApplAddr()</a>, <a class="el" href="a00025.html#a1873d6e3fc6d92cf8482b39f1c5ac6c8">BaseLayer::sendDown()</a>, and <a class="el" href="a00155.html#a8e95c523ae2e3136ab34313da7384dea">NetwControlInfo::setControlInfo()</a>.</p>

<p>Referenced by <a class="el" href="a00040.html#ae3bd389dede2510650cfb8b32d5716b4">BurstApplLayer::handleSelfMsg()</a>, <a class="el" href="a00041.html#aa50363ece763f8c35957ce60fab0d9a3">BurstApplLayerBattery::handleSelfMsg()</a>, and <a class="el" href="a00208.html#a7cc6a018758d27f31133de05804281f8">handleSelfMsg()</a>.</p>
<div class="fragment"><pre class="fragment">{
    ApplPkt *pkt = <span class="keyword">new</span> ApplPkt(<span class="stringliteral">&quot;BROADCAST_MESSAGE&quot;</span>, BROADCAST_MESSAGE);
    pkt-&gt;setDestAddr(<a class="code" href="a00117.html#a11d63e8d897e072ed94da77028d38f60" title="Broadcast address for L3 addresses.">LAddress::L3BROADCAST</a>);
    <span class="comment">// we use the host modules getIndex() as a appl address</span>
    pkt-&gt;setSrcAddr( <a class="code" href="a00016.html#a5b07d8afa4a3675a7e4c0d09dbbbddf3" title="Return my application layer address.">myApplAddr</a>() );
    pkt-&gt;setBitLength(<a class="code" href="a00016.html#ab42918350289ee246b194a5ab5e18d97" title="Length of the ApplPkt header.">headerLength</a>);

    <span class="comment">// set the control info to tell the network layer the layer 3</span>
    <span class="comment">// address;</span>
    <a class="code" href="a00155.html#a8e95c523ae2e3136ab34313da7384dea" title="Attaches a &quot;control info&quot; structure (object) to the message pMsg.">NetwControlInfo::setControlInfo</a>(pkt, <a class="code" href="a00117.html#a11d63e8d897e072ed94da77028d38f60" title="Broadcast address for L3 addresses.">LAddress::L3BROADCAST</a> );

    coreEV &lt;&lt; <span class="stringliteral">&quot;Sending broadcast packet!&quot;</span> &lt;&lt; endl;
    <a class="code" href="a00025.html#a1873d6e3fc6d92cf8482b39f1c5ac6c8" title="Sends a message to the lower layer.">sendDown</a>( pkt );
}
</pre></div>
</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>D:/Projects/MiXiM/extsrc/mixim/src/base/modules/<a class="el" href="a00280_source.html">TestApplLayer.h</a></li>
<li>D:/Projects/MiXiM/extsrc/mixim/src/base/modules/TestApplLayer.cc</li>
</ul>
</div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="a00208.html">TestApplLayer</a>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:33 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
